solid.Draw pic, LightSources, THE_AMBIENT_LIGHT, X, Y, Z
Next solid
pic.Refresh
End Sub
' Make a sphere.
Private Function Sphere(ByVal Cx As Single, ByVal Cy As Single, ByVal Cz As Single, ByVal radius As Single, ByVal num_horizontal As Integer, ByVal num_vertical As Integer) As Solid3d
Dim new_solid As Solid3d
Dim T As Integer
Dim theta1 As Single
Dim theta2 As Single
Dim dtheta As Single
Dim P As Integer
Dim phi1 As Single
Dim phi2 As Single
Dim dphi As Single
Dim x11 As Single ' xij: theta = i, phi = j
Dim y11 As Single
Dim z11 As Single
Dim x12 As Single
Dim y12 As Single
Dim z12 As Single
Dim x21 As Single
Dim y21 As Single
Dim z21 As Single
Dim x22 As Single
Dim y22 As Single
Dim z22 As Single
Dim R As Single
Set new_solid = New Solid3d
theta1 = 0
dtheta = 2 * PI / num_horizontal
For T = 1 To num_horizontal
theta2 = theta1 + dtheta
phi1 = -PI / 2
dphi = PI / num_vertical
x11 = 0
y11 = -radius
z11 = 0
x21 = 0
y21 = -radius
z21 = 0
For P = 1 To num_vertical
phi2 = phi1 + dphi
y12 = radius * Sin(phi2)
R = radius * Cos(phi2)
x12 = R * Cos(theta1)
z12 = R * Sin(theta1)
y22 = radius * Sin(phi2)
R = radius * Cos(phi2)
x22 = R * Cos(theta2)
z22 = R * Sin(theta2)
If P = 1 Then
' Bottom triangle.
new_solid.AddFace _
Cx + x11, Cy + y11, Cz + z11, _
Cx + x12, Cy + y12, Cz + z12, _
Cx + x22, Cy + y22, Cz + z22
ElseIf P = num_vertical Then
' Top triangle.
new_solid.AddFace _
Cx + x11, Cy + y11, Cz + z11, _
Cx + x12, Cy + y12, Cz + z12, _
Cx + x21, Cy + y21, Cz + z21
Else
' Middle rectangle.
new_solid.AddFace _
Cx + x11, Cy + y11, Cz + z11, _
Cx + x12, Cy + y12, Cz + z12, _
Cx + x22, Cy + y22, Cz + z22, _
Cx + x21, Cy + y21, Cz + z21
End If
x11 = x12
y11 = y12
z11 = z12
x21 = x22
y21 = y22
z21 = z22
phi1 = phi2
Next P
theta1 = theta2
Next T
new_solid.IsConvex = True
new_solid.HideSurfaces = True
new_solid.SetDiffuseCoefficients 1#, 1#, 1#
new_solid.SetAmbientCoefficients 1#, 1#, 1#
new_solid.SetSpecularCoefficients SPEC_K, SPEC_N
Set Sphere = new_solid
End Function
Private Sub chkLights_Click(Index As Integer)
Screen.MousePointer = vbHourglass
DoEvents
CreateLightSources
DrawData picCanvas
picCanvas.SetFocus
Screen.MousePointer = vbDefault
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)